/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Aplicacao.java
 *
 * Created on 08/07/2011, 16:45:00
 */
package grafos;

import grafos.Grafo.Global;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import javax.swing.UIManager;

/**
 *
 * @author rooke
 */
public class Aplicacao extends javax.swing.JFrame {

    Grafo g;

    /** Creates new form Aplicacao */
    public Aplicacao() {
        initComponents();

        String linha = null;
        int grau = 0;

        g = new Grafo();
        Vertice v = new Vertice();
        Aresta a = new Aresta();

        try {
            FileReader reader = new FileReader("grafo.txt");
            BufferedReader leitor = new BufferedReader(reader);
            StringTokenizer numero = null;
            StringTokenizer vert = null;
            ArrayList<String> numeros = new ArrayList<String>();

            while ((linha = leitor.readLine()) != null) {


                numero = new StringTokenizer(linha, ": -");


                while (numero.hasMoreTokens()) {

                    numeros.add(numero.nextToken());
                    //vert = new StringTokenizer(linha, "-");
                }
                //

            }
            leitor.close();
            reader.close();
            if (numeros.get(0).equals("0")) {
                // System.out.println("false");
                g.setOrientado(false);
            } else {
                if (numeros.get(0).equals("1")) {
                    //  System.out.println("true");
                    g.setOrientado(true);
                }
            }
            /****************************************************/
            /*** Faz a inserção dos vértices ***/
            /****************************************************/
            for (int i = 1; i < (numeros.size()); i = i + 3) {
                g.insereVertice(Integer.parseInt(numeros.get(i)));
                //  System.out.println(numeros.get(i));
            }
            //System.out.println("pares:  ");
            for (int i = 2; i < (numeros.size()); i = i + 3) {
                g.insereVertice(Integer.parseInt(numeros.get(i)));
                // System.out.println(numeros.get(i));
            }
            /****************************************************/
            /*** Faz a inserção das arestas***/
            /****************************************************/
            for (int i = 1; i < (numeros.size()); i = i + 3) {

                g.insereAresta(Integer.parseInt(numeros.get(i)), Integer.parseInt(numeros.get(i + 1)), Integer.parseInt(numeros.get(i + 2)));
                //System.out.println(numeros.get(i)+":"+numeros.get(i+1)+"-"+numeros.get(i+2));

            }

            System.out.println("oioioioi");





        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jTextField3 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jButton16 = new javax.swing.JButton();
        jButton17 = new javax.swing.JButton();
        jButton18 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jButton1.setText("existeCaminho(v1,v2)");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jButton2.setText("ordenaPesoArestas()");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        jButton3.setText("ordenaGrausVertices()");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        jButton4.setText("imprimeAdjacentes(v1)");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });

        jButton5.setText("imprimeSucessores(v1)");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });

        jButton6.setText("imprimeAntecessores(v1)");
        jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton6MouseClicked(evt);
            }
        });

        jButton7.setText("imprimeFTD(v1)");
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton7MouseClicked(evt);
            }
        });

        jButton8.setText("imprimeFTI(v1)");
        jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton8MouseClicked(evt);
            }
        });

        jLabel1.setText("Valor1:");

        jLabel2.setText("Valor2:");

        jButton9.setText("geraGrafoReduzido()");
        jButton9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton9MouseClicked(evt);
            }
        });

        jButton10.setText("imprimeGrafo()");
        jButton10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton10MouseClicked(evt);
            }
        });

        jButton11.setText("imprimeMatrizes()");
        jButton11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton11MouseClicked(evt);
            }
        });

        jButton12.setText("Dijkstra(v1)");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jButton13.setText("Coloracao()");
        jButton13.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton13MouseClicked(evt);
            }
        });

        jButton14.setText("BuscaProfundidade()");
        jButton14.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton14MouseClicked(evt);
            }
        });
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jButton15.setText("removeAresta(v1,v2,peso)");
        jButton15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton15MouseClicked(evt);
            }
        });

        jLabel3.setText("Peso:");

        jButton16.setText("insereAresta(v1,v2,peso)");
        jButton16.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton16MouseClicked(evt);
            }
        });

        jButton17.setText("removeVértice(v1)");
        jButton17.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton17MouseClicked(evt);
            }
        });

        jButton18.setText("insereVértice(v1)");
        jButton18.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton18MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton18, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton13, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton12, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton14, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton15, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 481, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 577, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton13)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked

        Vertice v1 = new Vertice();
        Vertice v2 = new Vertice();
        v1.setId(Integer.parseInt(jTextField1.getText()));
        v2.setId(Integer.parseInt(jTextField2.getText()));

        jTextArea1.setText("");
        jTextArea1.setText(Boolean.toString(g.existeCaminho(v1, v2)));

    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked

        g.OrdenaPesoArestas();
        ArrayList<Aresta> arestas = g.getArestas();

        jTextArea1.setText("");
        for (Aresta a : arestas) {
            jTextArea1.setText(jTextArea1.getText() + "\n" + a.getV1().getId() + "-" + a.getV2().getId() + ":" + a.getPeso());
        }

    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked

        ArrayList<Vertice> vertices = g.ordenaGrausVertices();
        ArrayList<Vertice> vertices1 = g.ordenaGrausVerticesEntrada();
        ArrayList<Vertice> vertices2 = g.ordenaGrausVerticesSaída();

        jTextArea1.setText("");
        if (!g.isOrientado()) {
            for (Vertice vertice : vertices) {
                jTextArea1.setText(jTextArea1.getText() + "\n" + vertice.getId() + "-" + g.CalculaGrau(vertice.getId()));
            }
        } else {
            jTextArea1.setText(jTextArea1.getText() + "\n" + "Ordenado por Grau de Saída:\n");
            for (Vertice vertice : vertices2) {
                jTextArea1.setText(jTextArea1.getText() + "\n" + vertice.getId() + "-" + g.CalculaGrauSaida(vertice.getId()));
            }
            jTextArea1.setText(jTextArea1.getText() + "\n" + "Ordenado por Grau de Entrada:\n");
            for (Vertice vertice : vertices1) {
                jTextArea1.setText(jTextArea1.getText() + "\n" + vertice.getId() + "-" + g.CalculaGrauEntrada(vertice.getId()));
            }
        }
    }//GEN-LAST:event_jButton3MouseClicked

    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked

        jTextArea1.setText("");
        ArrayList<Integer> ids = g.ImprimeAdjacentes(Integer.parseInt(jTextField1.getText()));
        for (Integer integer : ids) {
            jTextArea1.setText(jTextArea1.getText() + "\n" + integer);
        }


    }//GEN-LAST:event_jButton4MouseClicked

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked

        jTextArea1.setText("");
        ArrayList<Integer> ids = g.GeraSucessores(Integer.parseInt(jTextField1.getText()));
        for (Integer integer : ids) {
            jTextArea1.setText(jTextArea1.getText() + "\n" + integer);
        }
    }//GEN-LAST:event_jButton5MouseClicked

    private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton6MouseClicked

        jTextArea1.setText("");
        ArrayList<Integer> ids = g.GeraAntecessores(Integer.parseInt(jTextField1.getText()));
        for (Integer integer : ids) {
            jTextArea1.setText(jTextArea1.getText() + "\n" + integer);
        }

    }//GEN-LAST:event_jButton6MouseClicked

    private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton7MouseClicked
        // TODO add your handling code here:

        jTextArea1.setText("");


        Vertice v1 = new Vertice();
        v1.setId(Integer.parseInt(jTextField1.getText()));


        ArrayList<Integer> ids = g.geraFTD(v1);
        for (Integer integer : ids) {
            jTextArea1.setText(jTextArea1.getText() + "\n" + integer);
        }

    }//GEN-LAST:event_jButton7MouseClicked

    private void jButton8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton8MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");


        Vertice v1 = new Vertice();
        v1.setId(Integer.parseInt(jTextField1.getText()));


        ArrayList<Integer> ids = g.geraFTI(v1);
        for (Integer integer : ids) {
            jTextArea1.setText(jTextArea1.getText() + "\n" + integer);
        }
    }//GEN-LAST:event_jButton8MouseClicked

    private void jButton9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton9MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");
        ArrayList<int[]> componentes = new ArrayList<int[]>();
        componentes = g.geraGrafoReduzido(g);

        for (int valorComponente = 1; valorComponente < Global.c; valorComponente++) {
            jTextArea1.setText(jTextArea1.getText() + "\nComponente" + valorComponente + ": ");
            //System.out.print("\nComponente "+valorComponente+": ");
            for (int[] ar : componentes) {

                if (ar[1] == valorComponente) {
                    jTextArea1.setText(jTextArea1.getText() + "\n" + ar[0] + " ");
                }
                // System.out.print(ar[0]+" ");

            }

        }
    }//GEN-LAST:event_jButton9MouseClicked

    private void jButton10MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton10MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");

        if (g.isOrientado()) {
            jTextArea1.setText(jTextArea1.getText() + "1\n");
            //System.out.println("1");
        } else {
            // System.out.println("0");
            jTextArea1.setText(jTextArea1.getText() + "0\n");
        }

        for (Vertice vertice : g.getVertices()) {
            Vertice v = vertice;

            while (v.getAdjacente() != null) {
                //System.out.print(vertice.getId());
                jTextArea1.setText(jTextArea1.getText() + vertice.getId());
                // System.out.print("-");
                jTextArea1.setText(jTextArea1.getText() + "-");
                // System.out.print(v.getAdjacente().getId());
                jTextArea1.setText(jTextArea1.getText() + v.getAdjacente().getId());
                //System.out.print(":");
                jTextArea1.setText(jTextArea1.getText() + ":");

                //System.out.println(v.getAdjacente().getPeso());
                jTextArea1.setText(jTextArea1.getText() + v.getAdjacente().getPeso() + "\n");
                v = v.getAdjacente();

            }

        }
    }//GEN-LAST:event_jButton10MouseClicked

    private void jButton11MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton11MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");
        jTextArea1.setText(jTextArea1.getText() + "Matriz de Incidência:\n");
        String[][] matrizI = new String[g.getVertices().size() + 1][g.getArestas().size() + 1];
        matrizI = g.ImprimeMatrizdeIncidencia(g);

        for (int i = 0; i < g.getVertices().size() + 1; i++) {
            for (int j = 0; j < g.getArestas().size() + 1; j++) {
                jTextArea1.setText(jTextArea1.getText() + "  " + matrizI[i][j] + "   ");

            }
            jTextArea1.setText(jTextArea1.getText() + "\n");
        }
        jTextArea1.setText(jTextArea1.getText() + "\n");
        jTextArea1.setText(jTextArea1.getText() + "Matriz de Adjacência:\n");
        int[][] matrizA = new int[g.getVertices().size() + 1][g.getVertices().size() + 1];
        matrizA = g.ImprimeMatrizdeAdjacencia(g);

        for (int i = 0; i < g.getVertices().size() + 1; i++) {
            for (int j = 0; j < g.getVertices().size() + 1; j++) {
                jTextArea1.setText(jTextArea1.getText() + "  " + matrizA[i][j] + "   ");
                //System.out.print(matrizA[i][j] + " ");
            }
            jTextArea1.setText(jTextArea1.getText() + "\n");
        }

    }//GEN-LAST:event_jButton11MouseClicked

    private void jButton13MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton13MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");
        int cores[][] = new int[2][g.getVertices().size()];
        cores = g.Coloracao(g);
        for (int col = 0; col < cores[0].length; col++) {
            jTextArea1.setText(jTextArea1.getText() + "Vertice: " + cores[0][col] + "-" + "Cor: " + cores[1][col] + "\n");


        }
    }//GEN-LAST:event_jButton13MouseClicked

    private void jButton18MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton18MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");
        int v = Integer.parseInt(jTextField1.getText());
        g.insereVertice(v);
        ArrayList<Vertice> vertices = new ArrayList<Vertice>();
        vertices = g.getVertices();
        for (Vertice vertice : vertices) {
            jTextArea1.setText(jTextArea1.getText() + vertice.getId() + "\n");
        }
    }//GEN-LAST:event_jButton18MouseClicked

    private void jButton17MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton17MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");
        int v = Integer.parseInt(jTextField1.getText());
        g.removeVertice(v);
        ArrayList<Vertice> vertices = new ArrayList<Vertice>();
        vertices = g.getVertices();
        for (Vertice vertice : vertices) {
            jTextArea1.setText(jTextArea1.getText() + vertice.getId() + "\n");
        }
    }//GEN-LAST:event_jButton17MouseClicked

    private void jButton16MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton16MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");
        int v1 = Integer.parseInt(jTextField1.getText());
        int v2 = Integer.parseInt(jTextField2.getText());
        int p = Integer.parseInt(jTextField3.getText());
        g.insereAresta(v1, v2, p);
        ArrayList<Aresta> arestas = new ArrayList<Aresta>();
        arestas = g.getArestas();
        for (Aresta aresta : arestas) {
            jTextArea1.setText(jTextArea1.getText() + aresta.getV1().getId() + "-" + aresta.getV2().getId() + ":" + aresta.getV2().getPeso() + "\n");
        }
    }//GEN-LAST:event_jButton16MouseClicked

    private void jButton15MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton15MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");
        int v1 = Integer.parseInt(jTextField1.getText());
        int v2 = Integer.parseInt(jTextField2.getText());
        int p = Integer.parseInt(jTextField3.getText());
        g.removeAresta(v1, v2, p);
        ArrayList<Aresta> arestas = new ArrayList<Aresta>();
        arestas = g.getArestas();
        for (Aresta aresta : arestas) {
            jTextArea1.setText(jTextArea1.getText() + aresta.getV1().getId() + "-" + aresta.getV2().getId() + ":" + aresta.getV2().getPeso() + "\n");
        }

    }//GEN-LAST:event_jButton15MouseClicked

    private void jButton14MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton14MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("");
        ArrayList<Integer> visitados = new ArrayList<Integer>();

        int v1 = Integer.parseInt(jTextField1.getText());
        Vertice ve = new Vertice();
        ve.setId(v1);

        visitados = g.BuscaProfundidade(ve);
        for (int visitado : visitados) {
            jTextArea1.setText(jTextArea1.getText() + visitado + "\n");
        }

    }//GEN-LAST:event_jButton14MouseClicked

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        // TODO add your handling code here:

        jTextArea1.setText("");

        //imprime a matriz de menores distancias
        if (jTextField1.getText().equals("")) {

            for (Vertice ver : g.getVertices()) {

                ArrayList<int[]> d = g.djikstra(ver.getId());

                for(int[] is : d){

                    int tamanho = Integer.toString(is[1]).length();

                    if(tamanho == 1){
                        jTextArea1.setText(jTextArea1.getText() + "00000" + is[1] + "  ");
                    }else if(tamanho == 2){
                        jTextArea1.setText(jTextArea1.getText() + "0000" + is[1] + "  ");
                    }else if(tamanho == 3){
                        jTextArea1.setText(jTextArea1.getText() + "000" + is[1] + "  ");
                    }else if(tamanho == 4){
                        jTextArea1.setText(jTextArea1.getText() + "00" + is[1] + "  ");
                    }else{
                        jTextArea1.setText(jTextArea1.getText() + "" + is[1] + "  ");
                    }

                }

                jTextArea1.setText(jTextArea1.getText() + "\n");



            }




        } else {
            int v1 = Integer.parseInt(jTextField1.getText());

            ArrayList<int[]> d = g.djikstra(v1);

                for(int[] is : d){

                    int tamanho = Integer.toString(is[1]).length();

                    if(tamanho == 1){
                        jTextArea1.setText(jTextArea1.getText() + "00000" + is[1] + "  ");
                    }else if(tamanho == 2){
                        jTextArea1.setText(jTextArea1.getText() + "0000" + is[1] + "  ");
                    }else if(tamanho == 3){
                        jTextArea1.setText(jTextArea1.getText() + "000" + is[1] + "  ");
                    }else if(tamanho == 4){
                        jTextArea1.setText(jTextArea1.getText() + "00" + is[1] + "  ");
                    }else{
                        jTextArea1.setText(jTextArea1.getText() + "" + is[1] + "  ");
                    }

                }
        }


    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton14ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                try {
                    // Define layout de acordo com o SO que estiver rodando
                } catch (Exception e) {
                }

                //new Aplicacao().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JButton jButton18;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables
}
